package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.pms.entity.Idea;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;


public class IdeaDao {
private DBHelp<Idea> db = new DBHelp<Idea>();
	
	
	public List<Idea> findAll() {
		String sql = "select id,ideaname,text,t_project_id,createtime from t_idea";
		return db.executeQueryForList(sql, new IdeaRowMapper());
	}
	public void del(String id){
		String sql="delete from t_idea where id =?";
		db.executeSQL(sql, id);
	}
	public void udate(Idea idea){
		String sql = "update t_idea set  ideaname=?,text=?,createtime=? where id = ?";
		db.executeSQL(sql,idea.getIdeaname(),idea.getText(),idea.getCreatetime(),idea.getId());
	
	}
	public Idea findById(String id) {
		String sql = "select id,ideaname,text,t_project_id,createtime from t_idea where id = ?";
		return db.executeQueryForObject(sql, new IdeaRowMapper(), id);
	}
	
	public void save(String id,String ideaname,String text,String t_project_id,String createtime) {
		String sql = "insert into t_idea(id,ideaname,text,t_project_id,createtime) values(?,?,?,?,?)";
		db.executeSQL(sql,id,ideaname,text,t_project_id,createtime);
	}
	private class IdeaRowMapper implements RowMapper<Idea> {

		public Idea mapperRow(ResultSet rs) throws SQLException {
			Idea idea = new Idea();
			idea.setId(rs.getString("id"));
			idea.setIdeaname(rs.getString("ideaname"));
			idea.setText(rs.getString("text"));
			idea.setT_project_id(rs.getString("t_project_id"));
			idea.setCreatetime(rs.getString("createtime"));
			return idea;
		}
}}